@{
    Layout = null;
    ViewBag.Title = "小王软件";
    string Account = ViewData["AccountEval"] == null ? "" : ViewData["AccountEval"].ToString();
    string passWord = ViewData["PassWordEval"] == null ? "" : ViewData["PassWordEval"].ToString();
    string ReturnUrl = ViewData["ReturnUrl"] == null ? "" : ViewData["ReturnUrl"].ToString();
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>小王软件</title>
    <script src="~/lib/jquery/dist/jquery.js"></script>
    <script src="~/vue/js/vue.js"></script>
    <script src="~/vue/js/vue-resource.js"></script>
    <script src="~/vue/js/qs.js"></script>
    <script src="~/vue/js/axios.js"></script>
    <script src="~/vue/js/ElementUI/element-ui.js"></script>
    <link href="~/vue/css/ElementUI/element-ui.css" rel="stylesheet" />
    <link href="~/vue/css/login.css" rel="stylesheet" />
</head>
<body>
    @Html.AntiForgeryToken()
    <div id="login" class="login-div">
        <div class="login-card">
            <el-card>
                <label class="label-login">Login</label>
                <el-form ref="formData" label-width="60px" :model="formData">
                    <el-form-item label="单  位" class="el-form-select-div">
                        <el-select v-model="valuename" placeholder="请选择" ref="selects" :popper-append-to-body="false">
                            <el-option :value="valuename" class="setstyle" disabled>
                                <el-tree :data="optionData"
                                         :props="datalist"
                                         :node-key="datalist.value"
                                         accordion
                                         @@node-click="NodeClick"></el-tree>
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="用户名" class="el-form-text-div" prop="account">
                        <el-input type="text" v-model="formData.account"></el-input>
                    </el-form-item>
                    <el-form-item label="密　码" class="el-form-password-div" prop="password">
                        <el-input type="password" v-model="formData.password"></el-input>
                    </el-form-item>
                    <el-form-item style="margin-left: -60px;">
                        <el-button type="primary" style="font-size:18px; font-weight:bold" @@click="sub">登&nbsp;录</el-button>
                    </el-form-item>
                </el-form>
            </el-card>
        </div>
    </div>
</body>
</html>
<script type="text/javascript">
    window.onload = function () {
        new Vue({
            el: '#login',
            data: {
                formData: {
                    account: '',
                    password: ''
                },
                options: [],
                datalist: {
                    value: 'Id',
                    label: 'Name',
                    children: 'children',
                },
                valuename: '',
                valueid: '',
                ReturnUrl:''
            },
            mounted() {
                this.formData.account='@Account';
                this.formData.password = '@passWord';
                this.ReturnUrl = '@ReturnUrl';
                this.GetUnit();
            },
            created() {
                this.keyupSubmit();
            },
            methods: {
                sub() {
                    let ts = this;
                    if (this.formData.account == '' || this.formData.password=='') {
                        ts.$message.error({
                            iconClass: "zdy-message-img zdy-message-img-error",
                            customClass: "zdy-message-bk",
                            dangerouslyUseHTMLString: true,
                            offset: 50,
                            message: '<div class="zdy-message-content">用户名或密码不为空</div>'
                        });
                        return;
                    }
                    var token = $('[name=__RequestVerificationToken]').val();
                    axios({
                        method: 'post',
                        url: '/Admin/Login',
                        contentType: 'application/x-www-form-urlencoded', //请求数据类型
                        data: Qs.stringify({
                            __RequestVerificationToken: token,
                            UnitCode: this.valueid,
                            Account: this.formData.account,
                            Password: this.formData.password
                        })
                    }).then(function (response) {
                        var ress = response.data;
                        if (ress.state === "OK") {
                            ts.$message({
                                type: 'success',
                                iconClass: "zdy-message-img zdy-message-img-success",
                                customClass: "zdy-message-bk",
                                dangerouslyUseHTMLString: true,
                                offset: 50,
                                message: '<div class="zdy-message-content">' + ress.mc + '</div>'
                            });
                            if (ts.ReturnUrl != "" && ts.ReturnUrl != undefined) {
                                window.location.href = ts.ReturnUrl;
                            }
                            else {
                                window.location.href = ress.url;
                            }
                        } else {
                            ts.$message.error({
                                iconClass: "zdy-message-img zdy-message-img-error",
                                customClass: "zdy-message-bk",
                                dangerouslyUseHTMLString: true,
                                offset: 50,
                                message: '<div class="zdy-message-content">' + ress.mc + '</div>'
                            });
                        }
                    }).catch(function (error) {
                        console.log(error);
                    });

                },
                keyupSubmit() {
                    var _this = this;
                    document.onkeydown = function (e) {
                        let key = window.event.keyCode;
                        if (key === 13) {
                            _this.sub();
                        }
                    }
                },
                NodeClick(node) {
                    this.valuename = node.Name;
                    this.valueid = node.Id;
                },
                GetUnit() {
                    let _this = this;
                    axios.get('/Admin/GetUnitCode')
                        .then(function (response) {
                            _this.options = JSON.parse(JSON.stringify(response.data));
                            _this.valuename = _this.options[0].Name;
                            _this.valueid = _this.options[0].Id;
                        })
                        .catch(function (error) { // 请求失败处理
                            console.log(error);
                        });
                }
            },
            computed: {
                optionData() {
                    let cloneData = this.options;
                    return cloneData.filter(father => {
                        let branchArr = cloneData.filter(child => father.Id == child.PId);
                        branchArr.length > 0 ? father.children = branchArr : ''
                        return father.UnitClass == "1";
                    });
                },
            }
        })
    }
</script>